package DI;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;





//使用set方法
public class UserServiceTest {
//    public static void main(String[] args) {

//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//        //从容器中获取 userService对象    使用getBean("");来获取容器中存在的对象
//        //(1)通过bean的id属性值获取IOC容器中的对象
//        UserService userService = (UserService) applicationContext.getBean("userService");
//        userService.addUser();
//        //(2)通过bean的name属性值获取对象
//        UserService name1 = (UserService) applicationContext.getBean("name1");
//        System.out.println("name1");
//        name1.addUser();
//        UserService name2 = (UserService) applicationContext.getBean("name2");
//        System.out.println("name2");
//        name2.addUser();
//        UserService name3 = (UserService) applicationContext.getBean("name3");
//        System.out.println("name3");
//        name3.addUser();


//      //使用构造方法
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//        //获取 userService对象
//        UserService userService = (UserService) applicationContext.getBean("userService");
//        userService.addUser();
//    }



        @Test
        public void test1() {
            AnnotationConfigApplicationContext context= new AnnotationConfigApplicationContext(Config.class);
            for (String beanName : context.getBeanDefinitionNames()) {
                System.out.println(String.format("%s->%s", beanName, context.getBean(beanName)));
            }
        }
    }


